package com.fenghuo.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class UtilPrefference {

	public static final String settingfile="settings";//设置

	public static void write(Context context,String file,String key,String value){
		SharedPreferences preferences=context.getSharedPreferences(file, Context.MODE_PRIVATE);
		Editor edit = preferences.edit();
		edit.putString(key, value);
		edit.commit();
	}

	public static String getpreffer(Context context,String file,String key){
		SharedPreferences preferences=context.getSharedPreferences(file, Context.MODE_PRIVATE);
		return preferences.getString(key, null);
	}

	/**检查是否是第一次打开程序
	 * @param context
	 * @return
	 */
	public static boolean isfirst(Context context){
		SharedPreferences preferences=context.getSharedPreferences(settingfile, Context.MODE_PRIVATE);
		int time = preferences.getInt("Times", 0);
		if(time!=0){
			Editor edit = preferences.edit();
			edit.putInt("Times", time+1);
			edit.commit();
			return false;
		}else {
			Editor edit = preferences.edit();
			edit.putInt("Times", time+1);
			edit.commit();
			return true;
		}
	}
}
